import request from '../utils/request'

/**
 * 统计相关API接口
 */

export interface OverviewData {
  userCount: number
  articleCount: number
  activityCount: number
  spotCount: number
  orderCount: number
  orderAmount: number
  orderAmountGrowth: number
  userGrowth: number
  newOrderCount: number
}

export interface TrendData {
  date: string
  value: number
}

export interface OrderStatData {
  date: string
  count: number
  amount: number
}

export interface UserGenderData {
  gender: 'male' | 'female' | 'unknown'
  count: number
}

export interface UserAgeData {
  ageRange: string
  count: number
}

export interface ContentStats {
  category: string
  count: number
  viewCount: number
}

export interface PopularActivity {
  id: string
  title: string
  signupCount: number
  maxParticipants: number
  startTime: string
  category: string
}

export interface PopularSpot {
  id: string
  name: string
  visitCount: number
  category: string
}

/**
 * 获取平台概览数据
 */
export function getOverviewData() {
  return request<OverviewData>({
    url: '/statistics/overview',
    method: 'GET'
  })
}

/**
 * 获取用户增长趋势
 * @param period 时间周期：week, month, year
 */
export function getUserTrend(period: 'week' | 'month' | 'year' = 'month') {
  return request<TrendData[]>({
    url: '/statistics/user-trend',
    method: 'GET',
    params: { period }
  })
}

/**
 * 获取内容增长趋势
 * @param contentType 内容类型：article, activity, spot
 * @param period 时间周期：week, month, year
 */
export function getContentTrend(
  contentType: 'article' | 'activity' | 'spot',
  period: 'week' | 'month' | 'year' = 'month'
) {
  return request<TrendData[]>({
    url: '/statistics/content-trend',
    method: 'GET',
    params: { contentType, period }
  })
}

/**
 * 获取订单统计数据
 * @param period 时间周期：week, month, year
 */
export function getOrderStats(period: 'week' | 'month' | 'year' = 'month') {
  return request<OrderStatData[]>({
    url: '/statistics/order-stats',
    method: 'GET',
    params: { period }
  })
}

/**
 * 获取用户性别分布
 */
export function getUserGenderDistribution() {
  return request<UserGenderData[]>({
    url: '/statistics/user-gender',
    method: 'GET'
  })
}

/**
 * 获取用户年龄分布
 */
export function getUserAgeDistribution() {
  return request<UserAgeData[]>({
    url: '/statistics/user-age',
    method: 'GET'
  })
}

/**
 * 获取内容分类统计
 * @param contentType 内容类型：article, activity, spot
 */
export function getContentCategoryStats(contentType: 'article' | 'activity' | 'spot') {
  return request<ContentStats[]>({
    url: '/statistics/content-category',
    method: 'GET',
    params: { contentType }
  })
}

/**
 * 获取热门活动
 * @param limit 限制数量
 */
export function getPopularActivities(limit: number = 5) {
  return request<PopularActivity[]>({
    url: '/statistics/popular-activities',
    method: 'GET',
    params: { limit }
  })
}

/**
 * 获取热门景点
 * @param limit 限制数量
 */
export function getPopularSpots(limit: number = 5) {
  return request<PopularSpot[]>({
    url: '/statistics/popular-spots',
    method: 'GET',
    params: { limit }
  })
} 